/*
============================================================================
 Name        : ShoutcastReader.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CShoutcastReader declaration
============================================================================
*/

#ifndef __SHOUTCASTREADER_H__
#define __SHOUTCASTREADER_H__

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include "StreamReader.h"

class MShoutcastReaderObserver
{
public:
	virtual void OnServerNameChanged(const TDesC& aServerName) = 0;
	virtual void OnMetadataChanged(const TDesC& aMetadata) = 0;
};

class CShoutcastReader : public CStreamReader
{
private: //Constructor
	CShoutcastReader(MShoutcastReaderObserver& aObserver);
	void ConstructL();

public: // Constructors and destructor
	~CShoutcastReader();
	static CShoutcastReader* NewL(MShoutcastReaderObserver& aObserver);
	static CShoutcastReader* NewLC(MShoutcastReaderObserver& aObserver);


private: //from CStreamReader
	const TDesC8& GetAdditionalHeadersL();
	TDesC8& ParseResponseL(TDesC8& aChunk);


public: //new functions
	const TDesC& GetServerName();


private: //new functions
	void ParseLineL(TDesC8& aLine);
	TBool GetHeaderValueL(TDesC8& aLine, const TDesC8& aKey, TDes* value);
	TBool GetHeaderValueL(TDesC8& aLine, const TDesC8& aKey, TDes8* value);
	TBool GetHeaderValueL(TDesC8& aLine, const TDesC8& aKey, TInt* value);
	TInt GetReceivedDataL(TUint8* aBufferToDecode, TInt aLength);
	void ParseMetadataL(TDesC8& aMetadata);


private: //data
	//Observer
	MShoutcastReaderObserver& iObserver;

	//Metadata
	TBuf<256> iServerName;
	TBuf<256> iMetadata;

	TInt iMetaint;
	TInt iBitRate;

	TInt iNextMetadataPos;

	//Pointer to buffer to decode
	TPtr8 iBufferToDecodePtr;

	
};

#endif // __SHOUTCASTREADER_H__
